<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html lang="en">
  <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="网络程序设计(苏航)-期末作业">
    <meta name="author" content="赵云雷">
    <meta name="student number" content="18061119">
    <title>云雷书店</title>


    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" ></script>


    <style>
      .bd-placeholder-img {
        font-size: 1.125rem;
        text-anchor: middle;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
      }

      @media (min-width: 768px) {
        .bd-placeholder-img-lg {
          font-size: 3.5rem;
        }
      }
      .mybutton{
          display:flex;
      }
    </style>

    
    <!-- Custom styles for this template -->
    <link href="jumbotron.css" rel="stylesheet">
  </head>
  <body>
    <%@ include file="tabBar.jsp"%>
    
    
    <div class="jumbotron">
    <table class="table">
        <thead class="thead-dark">
        <tr>
            <th scope="col">编号</th>
            <th scope="col">名字</th>
            <th scope="col">单价</th>
            <th scope="col">购买数量</th>
            <th scope="col">总价</th>
        </tr>
        </thead>
        <tbody>
            <% double sumPrice = 0,price = 0; %>
            <%DecimalFormat df = new DecimalFormat("0.00");%>
            <% ArrayList<ArrayList<String>> goodsDetail = (ArrayList)session.getAttribute("goodsDetail");%>
            <% int index =1; %>
            <% if(goodsDetail != null ){ %>
            <% for (ArrayList<String> i : goodsDetail) {%>
                <tr>
                    <td><%=index%></td>
                    <td><%=i.get(1)%></td>
                    <td><%=i.get(3)%></td>
                    <td><%=i.get(6)%></td>
                    <% price = Double.parseDouble(i.get(3))*Double.parseDouble(i.get(6));%>
                    <% sumPrice += price;%>
                    <td><%=df.format(price)%></td>
                </tr>
                <% index++; %>
                
            <%}%>
            <%}%>
        </tbody>
    </table>
    
    <h1 class="display-3">总价格为:<%=df.format(sumPrice)%></h1>
    <div class="mybutton">
        <form method="post" action="control?page=cart&submit=order" style="margin-right: 20px;">
            <input type="hidden" name="sumprice" value="<%=sumPrice%>">
            <%SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间 
              sdf.applyPattern("yyyy-MM-dd HH:mm:ss a");// a为am/pm的标记  
              Date date = new Date();// 获取当前时间 %>
            <input type="hidden" name="date" value="<%=sdf.format(date)%>">
            <button type="submit" class="btn btn-primary">提交订单</button>
        </form>
        <form method="post" action="control?page=cart&submit=clear">
            <button type="submit" class="btn btn-primary">清空购物车</button>
        </form>
    </div>
    
    </div>
  </body>
</html>
